#ifndef SP_DBUS_CONTEXT_HPP
#define SP_DBUS_CONTEXT_HPP

#include <systemd/sd-bus.h>
#include <string>
#include <vector>

class DbusContext
{
public:
    explicit DbusContext(
        const std::string& aServiceName, const std::string& aServicePath, const std::string& aServiceInterface);

    virtual ~DbusContext();

    void run();

    virtual bool prepare() = 0;

    inline std::string getServiceName() {
        return mServiceName;
    }

    inline std::string getServicePath() {
        return mServicePath;
    }

    inline std::string getServiceInterface() {
        return mServiceInterface;
    }

    inline sd_bus* getDbus() {
        return mDbus;
    }

    inline sd_event* getEvent() {
        return mEvent;
    }

    inline std::vector<sd_bus_slot*>& getSlots() {
        return mSlots;
    }

private:
    bool init();

    bool eventloop();

    std::string mServiceName;
    
    std::string mServicePath;

    std::string mServiceInterface;

    sd_bus* mDbus { nullptr };

    sd_event* mEvent { nullptr };

    std::vector<sd_bus_slot*> mSlots;
};

#endif